<template>
	<view class="goods-item">
		<!-- 商品左侧图片区域 -->
		<view class="goods-item-left">
			<radio :checked="goods.isChecked" color="#ff7d00" @click="radioClickHandler"></radio>
			<image :src="goods.imgSrc || defaultPic" class="goods-pic" mode="aspectFit"></image>
		</view>
		<!-- 商品右侧信息区域 -->
		<view class="goods-item-right">
			<view class="goods-name">{{goods.name}}</view>
			<view class="goods-info-box">
				<view class="sponsor">发起人：{{goods.sponsor}}</view>
				<uni-number-box :min="1" :value="goods.num" @change="numChangeHandler">
				</uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			goods: {
				type: Object,
				default: {},
			},
		},
		data() {
			return {
				// 默认的空图片
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};

		},

		methods: {
			// radio 组件的点击事件处理函数
			radioClickHandler() {
				this.$emit('radio-change', {
					id: this.goods.id,
					isChecked: !this.goods.isChecked
				})
			},
			numChangeHandler(val) {
				this.$emit('num-change', {
					id: this.goods.id,
					num: +val
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;

		.goods-item-left {
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.goods-pic {
				width: 100px;
				height: 100px;
				display: block;
			}
		}

		.goods-item-right {
			display: flex;
			flex: 1;
			flex-direction: column;
			justify-content: space-between;
			padding: 10px 0;

			.goods-name {
				font-size: 20px;
			}

			.goods-info-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			.sponsor {
				font-size: 16px;
				color: #ababab;
			}
		}
	}
</style>